<template>
    <div class="button-group" v-if="showSave && isShow">
        <Button type="primary" @click="saveBtnAction" :loading="loading">保存</Button>
    </div>
</template>

<script>
import { saveAndUpdateUser } from '@/api/record'

export default {
  name: 'CommonSaveBtn',
  props: {
    showSave: {
      type: Boolean,
      default: () => {
        return true
      }
    },
    formData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      loading: false,
      isShow: true
    }
  },
  methods: {
    saveBtnAction () {
      this.$emit('saveAction')
    },
    saveForm (data) {
      this.loading = true
      let saveData = this.formData
      if (data) {
        saveData = data
      }
      saveAndUpdateUser(saveData).then(res => {
        this.loading = false
        if (res.data.errcode === 0) {
          this.$Message.info('保存成功')
          this.$emit('result', res.data.data.res)
        } else {
          this.$Message.error('保存失败!')
        }
      }).catch(ret => {
        this.loading = false
        this.$Message.error(ret)
      })
    }
  },
  mounted () {
    let info = this.$route.query.what
    if (info === 'info') {
      this.isShow = false
    }
  }
}
</script>

<style scoped>

</style>
